Skip to main content

Audio

Example​

The sound is played, then played again with a pause, then its volume goes down while it plays.

import olem

SOUND = "/common/sounds/boot.wav"

# Play the sound until its end
olem.audio_play_file(SOUND)
olem.audio_wait_end_of_playback()

# Pause it for 2 s
olem.audio_play_file(SOUND)
olem.delay_ms(1000)
olem.audio_pause()
olem.delay_ms(2000)
olem.audio_resume()
olem.audio_wait_end_of_playback()

# Lower the volume while it plays
olem.audio_play_file(SOUND)
olem.audio_volume_enable(True)
for i in range(10, 0, -1):
olem.audio_volume_set(i / 10)
olem.delay_ms(200)
olem.audio_wait_end_of_playback()
olem.audio_volume_enable(False)

Functions​

audio_play_file(file_name)​

Play an audio file. The sound being played, if any, is stopped. Returns immediately, see audio_wait_end_of_playback().

ParameterDescription
file_namepath of the audio file, relative to the assets folder of the game

audio_is_playing()​

Returns: True if a sound is being played, False otherwise

audio_wait_end_of_playback()​

Wait for the end of the sound being played. Returns immediately if no sound is played. The game can still be stopped during the wait.

audio_stop()​

Stop the sound being played.

audio_pause()​

Pause the sound being played, see audio_resume().

audio_resume()​

Resume the sound paused with audio_pause().

audio_mute(mute)​

Mute or unmute the sound.

ParameterDescription
muteTrue to mute, False to unmute

audio_volume_set(volume)​

Set the volume of the game sounds. The volume chosen in OLEM's settings still applies on top of it.

ParameterDescription
volumefrom 0.0 (muted) to 1.0 (maximum)

audio_volume_get()​

Returns: volume set with audio_volume_set(), from 0.0 to 1.0

audio_volume_enable(enable)​

Enable or disable the volume set with audio_volume_set().

ParameterDescription
enableTrue to enable, False to disable

audio_white_noise_enable(enable)​

Start or stop playing white noise.

ParameterDescription
enableTrue to start, False to stop

audio_white_noise_amplitude_set(amplitude)​

Set the loudness of the white noise.

ParameterDescription
amplitudefrom 0.0 to 1.0, fraction of the maximum amplitude

audio_white_noise_amplitude_get()​

Returns: amplitude set with audio_white_noise_amplitude_set(), from 0.0 to 1.0